<template>
	<view class="voucher">
		<view class="dd-head">
			<view :class="asitemindex==item.status?'dd-sitem':'dd-item'" v-for="(item,index) in answer" :key="index"
				@tap="asitembtn(item)">
				<text>{{item.name}}</text>
			</view>
		</view>
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption"
			:up="upOption" height="0" style="min-height: 0;">
			<view class="voucher_list">
				<view class="voucher_list_item" v-for="(item,index) in list" :key="index">
					<view class="voucher_list_item_top">
						<view class="voucher_list_item_top_left"
							:class="[item.type==3?'voucher_list_item_top_secondly':item.type==2?'voucher_list_item_top_thirdly':(item.type==4 || item.type == 6 || item.type == 7)&&'voucher_list_item_top_fourthly',asitemindex!=0&&'voucher_list_item_top_extra']">
							<view class="voucher_list_item_top_left_money">
								<text class="voucher_list_item_top_left_money_sign"
									:style="asitemindex!=0?'color:#fff':''">￥</text>
								<text class="voucher_list_item_top_left_money_amount"
									:style="asitemindex!=0?'color:#fff':''">{{Number(item.reducePrice)}}</text>
							</view>
							<text class="voucher_list_item_top_left_fullmoney"
								:style="asitemindex!=0?'color:#fff':''">满{{item.minPrice}}元</text>
						</view>
						<view class="voucher_list_item_top_right">
							<view class="voucher_list_item_top_right_information">
								<view class="voucher_list_item_top_right_information_effect">
									<text class="voucher_list_item_top_right_information_effect_left"
										:class="[asitemindex!=0&&'voucher_list_item_top_right_information_effect_used']">{{item.name}}</text>
									<text v-if="item.type==3||item.type==4 || item.type==7 || item.type ==6"
										class="voucher_list_item_top_right_information_effect_right"
										:class="[(item.type==4 || item.type == 6 || item.type == 7)&&'voucher_list_item_top_right_information_effect_vipright',asitemindex!=0&&'voucher_list_item_top_right_information_effect_used']"
										:style="asitemindex!=0?'color:#999;border:1px solid #999':''">{{item.superimpose==1?'可叠加':'不可叠加'}}</text>
									<!-- <text v-if="item.type==4 || item.type==7 || item.type ==6"
										class="voucher_list_item_top_right_information_effect_right voucher_list_item_top_right_information_effect_vipright"
										:class="[(item.type==4 || item.type == 6 || item.type == 7)&&'voucher_list_item_top_right_information_effect_vipright',asitemindex!=1&&'voucher_list_item_top_right_information_effect_used']"
										:style="asitemindex!=1?'color:#999;border:1px solid #999':''">{{item.superimpose?'可组合':'不可组合'}}</text> -->
								</view>
								<view class="voucher_list_item_top_right_information_cxtravalue">
									<text v-if="asitemindex != 2"
										class="voucher_list_item_top_right_information_time">有效期至
										{{item.endTimeText}}</text>
									<text v-else class="voucher_list_item_top_right_information_time">有效期至
										{{ item.endTimeText}}</text>

									<view class="voucher_list_item_top_right_boximage" v-if="asitemindex==1">
										<image src="@/static/my/used.png" mode=""></image>
									</view>
									<view class="voucher_list_item_top_right_boximage" v-if="asitemindex==3">
										<image src="@/static/my/stale.png" mode=""></image>
									</view>
									<view class="voucher_list_item_top_right_boximage" v-if="asitemindex==2">
										<image src="@/static/my/ylq.png" mode=""></image>
									</view>
								</view>


								<view class="voucher_list_item_top_right_information_cxtravalue">
									<text v-if="asitemindex==0"
										class="voucher_list_item_top_right_information_amount">现有{{item.count}}张使用</text>
									<text v-if="asitemindex==1"
										class="voucher_list_item_top_right_information_amount voucher_list_item_top_right_information_used">已使用{{item.count}}张</text>
									<text v-if="asitemindex==2"
										class="voucher_list_item_top_right_information_amount">已分享{{item.count}}张给好友</text>
									<text v-if="asitemindex==3"
										class="voucher_list_item_top_right_information_amount voucher_list_item_top_right_information_stale">已过期{{item.count}}张</text>
									<view style="display: flex;" v-if="asitemindex==0">
										<view @click="shareCoupon(item)" class="vocher_share"
											v-if="asitemindex==0 && item.isCanShare == 1">
											分享</view>
										<view class="voucher_list_item_top_right_status">
											<text @click="goHome"
												v-if="asitemindex==0 && (!item.rechargeMoney||(Number(item.rechargeMoney)<=100))"
												class="voucher_list_item_top_right_status_text"
												:class="[item.type==3?'voucher_list_item_top_right_status_secondly':item.type==2?'voucher_list_item_top_right_status_thirly':(item.type==4 || item.type == 6 || item.type == 7)&&'voucher_list_item_top_right_status_fourthly']">立即使用</text>
										</view>
									</view>
								</view>

								<!-- <text>{{item.recharge_money}}</text> -->
							</view>
							<!-- <view class="voucher_list_item_top_right_status">
								<text @click="goHome" v-if="asitemindex==1&&(item.out_of_principal==0||item.type!=3||item.type==3&&(!item.recharge_money||(Number(item.recharge_money)<=100)))" class="voucher_list_item_top_right_status_text" :class="[item.type==3?'voucher_list_item_top_right_status_secondly':item.type==2?'voucher_list_item_top_right_status_thirly':item.type==4&&'voucher_list_item_top_right_status_fourthly']">立即使用</text>
							</view> -->
							<!-- <view class="voucher_list_item_top_right_boximage" v-if="asitemindex==3">
								<image src="@/static/my/used.png" mode=""></image>
							</view>
							<view class="voucher_list_item_top_right_boximage" v-if="asitemindex==4">
								<image src="@/static/my/stale.png" mode=""></image>
							</view> -->
						</view>
					</view>
					<view class="voucher_list_item_bottom">
						<view class="voucher_list_item_bottom_condition">
							<text class="voucher_list_item_bottom_condition_text"
								:class="[item.isImage&&'voucher_list_item_bottom_condition_extext']">
								{{item.useRule}}
							</text>
						</view>
						<view class="" @click="switchover(item)">
							<view class="voucher_list_item_bottom_imageview">
								<image class="voucher_list_item_bottom_image"
									:class="[item.isImage&&'voucher_list_item_bottom_eximage']"
									src="@/static/my/pulldown.png" mode=""></image>

							</view>
						</view>
					</view>
				</view>
			</view>
		</mescroll-body>
		<view class="bounced" v-if="showModal">
			<view class="bounced-box">
				<view class="bb-content">
					<view class="c-title">分享数量</view>
					<input class="c-input" type="number" v-model="shareNum" @input="shareInput" />
					<view class="c-hint">提示：当被分享者领取后，优惠券被减扣。</view>
				</view>
				<view class="btn">
					<view class="cancel" @click="cancel">
						取消
					</view>
					<view class="confirm" @click="submitShare">
						确认
					</view>
				</view>
			</view>
		</view>
		
	</view>
</template>

<script>
	import MescrollMixin from "@/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin],
		data() {
			return {
				asitemindex: 0,
				// 0：未使用，1：已使用，2：已分享，3：已过期
				answer: [{
						name: '未使用',
						status: 0,
					},
					{
						name: '已使用',
						status: 1
					},
					{
						name: '已分享',
						status: 2
					},
					{
						name: '已过期',
						status: 3
					}
				],
				// 下拉刷新的组件 参数 可以 改变的
				downOption: {
					use: false,
					auto: true //是否在初始化后,自动执行downCallback; 默认true
				},
				upOption: {
					page: {
						num: 0,
						size: 10,
						time: null
					},
					auto: true, // 不自动加载
					noMoreSize: 10, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
					empty: {
						tip: '暂无抵扣券', // 提示
						icon: '/static/my/discounts_empty.png'
					},
					textNoMore: '—— 没有更多抵扣券了 ——'
				},
				list: [],
				showModal: false,
				show: true,
				itemValue: null, //分享的父类数据
				shareNum: 1, //分享的数量
				userInfo: {}, //用户信息
			}
		},
		computed: {
			changList() {
				return function(item) {
					if (item.isImage) {
						return item.rulesList
					} else {
						let c = item.rulesList.filter((itemv, indexv) => {
							return indexv == 0
						})
						return c
					}
				}
			}
		},
		filters: {
			conversionTime: function(value) {
				let time = Number(value) * 1000;
				const dt = new Date(time)
				const y = dt.getFullYear()
				const m = (dt.getMonth() + 1 + '').padStart(2, '0')
				const d = (dt.getDate() + '').padStart(2, '0')
				const hh = (dt.getHours() + '').padStart(2, '0')
				const mm = (dt.getMinutes() + '').padStart(2, '0')

				return `${y}-${m}-${d} ${hh}:${mm}`
			}
		},
		onLoad() {
			this.upCallback({num:0,size:999999});
		},
		methods: {
			asitembtn(item) {
				this.asitemindex = item.status
				this.list = []
				// this.mescroll.resetUpScroll()
				this.upCallback({num:0,size:999999});
			},
			switchover(item) {
				item.isImage = !item.isImage
			},
			shareCoupon(item) {
				this.itemValue = item;
				this.shareNum = 1;
				this.showModal = true;
			},
			cancel() {
				this.showModal = false;
			},
			submitShare() {
				if (this.shareNum > this.itemValue.count || this.shareNum < 1) {
					uni.showToast({title: '请输入正确数量的分享券'});
					return
				}
				let self = this;
				self.itemValue['_num'] = this.shareNum;
				// this.gotoPage(`/userpage/userinfo/shareDetail?item=${ JSON.stringify(self.itemValue)}`)
				uni.showLoading({
					title: '加载中'
				})
				self.loading = true;
				self._post('user/coupon/share', {
					couponId:self.itemValue.couponId,
					shareNum:self.shareNum,
					
				}, function(res) {
					const { msg,data } = res;
					console.log(msg,data,'2345234')
					if(msg == '操作成功'){
						self.gotoPage(`/userpage/userinfo/shareDetail?item=${ JSON.stringify(self.itemValue)}&id=${data}`)
					}
				});
				
			},
			shareInput(e) {
				this.$nextTick(() => {
					if (e.target.value > this.itemValue.num) {
						this.shareNum = this.itemValue.num;
					}
				})
			},
			//下拉刷新 不需要开启
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			// 跳转到首页
			goHome() {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			// 上拉加载
			upCallback(page) {

				let self = this;
				uni.showLoading({
					title: '加载中'
				});
				self._postBody('user/coupon/lists', {
					dataType: self.asitemindex,
					pageIndex: page.num,
					pageSize: page.size,
					isHx: false, //是否核销

				}, function(res) {
					console.log(res);
					const {
						data
					} = res;
					if (!data.records) {
						data.records = []
					}
					let curPageLen = data.records.length;
					let totalPage = Number(data.total) / page.pageSize;
					if (page.num == 1) self.list = [];
					data.records.map(item => {
						item.isImage = false
					})
					self.list = data.records;
					self.mescroll.endByPage(curPageLen, totalPage)
				});




			}
		}
	}
</script>
<style scoped>
	/deep/.empty-icon {
		margin: 0 auto;
	}
</style>
<style lang="less" scoped>
	.dd-head {
		display: flex;
		justify-content: space-between;
		padding: 0rpx 54rpx;
		line-height: 84rpx;
		border-bottom: 1px solid rgba(238, 238, 238, 1);
		z-index: 99;
		position: sticky;
		top: var(--window-top);
		position: -webkit-sticky;
		background: #FFFFFF;
	}

	.dd-sitem {
		font-size: 34rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 500;
		line-height: 84rpx;
		color: #077840;
		border-bottom: 4rpx solid #077840;
	}

	.dd-item {
		font-size: 34rpx;
		font-family: PingFangSC-Regular, PingFang SC;
		font-weight: 400;
		color: #333333;
		line-height: 84rpx;
	}

	.voucher_list {
		margin-top: 46rpx;
		padding: 0 30rpx;
		padding-bottom: 10rpx;

		&_item {
			padding: 0 20rpx;
			margin-top: 30rpx;
			box-shadow: 0px 0px 12px 0px rgba(91, 74, 40, 0.1);
			border-radius: 8rpx;

			&_top {
				padding: 24rpx 0;
				display: flex;
				align-items: flex-start;

				&_left {
					width: 188rpx;
					height: 152rpx;
					background: linear-gradient(90deg, #0DA057 0%, #077840 100%);
					border-radius: 12rpx;
					display: flex;
					flex-direction: column;
					justify-content: center;
					align-items: center;
					margin-right: 20rpx;

					&_money {
						display: flex;
						align-items: center;

						&_sign {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #FFFFFF;
							line-height: 34rpx;
							margin-top: 30rpx;
						}

						&_amount {
							font-size: 60rpx;
							font-family: PingFangSC-Medium, PingFang SC;
							font-weight: 500;
							color: #FFFFFF;
							line-height: 84rpx;
						}
					}

					&_fullmoney {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						line-height: 34rpx;
					}
				}

				&_secondly {
					background: linear-gradient(90deg, #FF9800 0%, #FF4E00 100%);
				}

				&_thirdly {
					background: linear-gradient(90deg, #5BB6FB 0%, #2F80F6 100%);
				}

				&_fourthly {
					background: linear-gradient(315deg, #F6E3B8 0%, #DAB279 100%);

					.voucher_list_item_top_left_money_sign {
						color: #735116;
					}

					.voucher_list_item_top_left_money_amount {
						color: #735116;
					}

					.voucher_list_item_top_left_fullmoney {
						color: #735116;
					}
				}

				&_extra {
					background: #C8C8C8;
				}

				&_right {
					display: flex;
					// justify-content: space-between;
					// align-items: center;
					flex: 1;
					min-height: 152rpx;

					&_information {
						flex: 1;
						display: flex;
						flex-direction: column;
						justify-content: space-between;

						&_effect {
							display: flex;
							align-items: flex-start;

							&_left {
								flex: 1;
								font-size: 28rpx;
								font-family: PingFangSC-Medium, PingFang SC;
								font-weight: 500;
								color: #333333;
								line-height: 40rpx;
								margin-right: 8rpx;
							}

							&_right {
								width: 98rpx;
								height: 32rpx;
								background: #FFFFFF;
								border-radius: 4rpx;
								border: 2rpx solid #FF5100;
								font-size: 20rpx;
								font-family: PingFangSC-Regular, PingFang SC;
								font-weight: 400;
								color: #FF5100;
								line-height: 28rpx;
								text-align: center;
								box-sizing: border-box;
								margin-top: 4rpx;
							}

							&_vipright {
								margin-left: 16rpx;
							}

							&_used {
								border-color: #C8C8C8;
								color: #C8C8C8;
							}

							&_vipright {
								border-color: #735116;
								color: #735116;
							}

							&_stale {
								background-color: #C8C8C8;
							}
						}

						&_cxtravalue {
							display: flex;
							align-items: center;
							justify-content: space-between;
						}

						&_time {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							line-height: 34rpx;
						}

						&_amount {
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							line-height: 34rpx;
						}

						&_used {
							color: #999999;
						}

						&_stale {
							color: #999999;
						}
					}

					&_status {
						display: flex;
						align-items: center;

						&_text {
							width: 124rpx;
							height: 48rpx;
							background: #FFFFFF;
							border-radius: 26rpx;
							border: 2rpx solid #077840;
							font-size: 22rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #077840;
							line-height: 44rpx;
							text-align: center;
							box-sizing: border-box;
						}

						&_secondly {
							border: 2rpx solid #FF5100;
							color: #FF5100;
						}

						&_thirly {
							border: 2rpx solid #2F80F6;
							color: #2F80F6;
						}

						&_fourthly {
							border: 2rpx solid #242C3B;
							color: #242C3B;
						}
					}

					&_boximage {
						width: 136rpx;
						display: flex;
						align-items: center;

						image {
							width: 136rpx;
							height: 114rpx;
							vertical-align: top;
						}
					}
				}
			}

			&_bottom {
				padding: 24rpx 0;
				border-top: 2rpx dashed #E5E5E5;
				display: flex;
				justify-content: space-between;

				&_condition {
					display: flex;
					flex-direction: column;
					width: calc(100% - 50rpx);

					&_text {
						font-size: 24rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #999999;
						line-height: 34rpx;
						margin-bottom: 20rpx;
						overflow: hidden;
						text-overflow: ellipsis;
						white-space: nowrap;
					}

					&_extext {
						overflow: inherit;
						text-overflow: inherit;
						white-space: inherit;
					}
				}

				&_imageview {
					height: 34rpx;
					width: 44rpx;
					margin-right: -10rpx;
					display: flex;
					align-items: center;
					justify-content: center;
				}

				&_image {
					width: 24rpx;
					height: 14rpx;
					vertical-align: top;
					// margin-top: 10rpx;
					// margin-left: 24rpx;
					transform: rotate(0);
					// transition: 0.3s ease-in-out;
				}

				&_eximage {
					transform: rotate(-180deg);
				}
			}
		}
	}

	// 分享
	// .voucher {
	// 	position: relative;
	// }
	.vocher_share {
		font-size: 22rpx;
		line-height: 48rpx;
		background: #FFFFFF;
		border: 1px solid gray;
		// padding: 8rpx 20rpx;
		padding: 0 18rpx;
		border-radius: 26rpx;
		margin-right: 20rpx;
		// cursor: pointer;
	}

	.bounced {
		width: 100%;
		height: 100%;
		background: rgba(0, 0, 0, .75);
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9999;

		.bounced-box {
			width: 560rpx;
			// height: 386rpx;
			background: #FFFFFF;
			border-radius: 16rpx;
			position: absolute;
			top: 32%;
			left: 12%;
			overflow: hidden;

			.bb-content {
				padding: 40rpx 24rpx;
				border-bottom: 1px solid #E5E5E5;
				box-sizing: border-box;

				.c-title {
					height: 50rpx;
					font-size: 36rpx;
					font-family: PingFang SC-Medium, PingFang SC;
					font-weight: 600;
					color: #333333;
					line-height: 50rpx;
					text-align: center;
				}

				.c-input {
					border-radius: 2rpx;
					opacity: 1;
					border-bottom: 2rpx solid #E4E4E4;
					margin: 40rpx 0 20rpx;
					font-size: 34rpx;
					height: 66rpx;
				}

				.c-hint {
					height: 34rpx;
					font-size: 24rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #999999;
					line-height: 34rpx;
				}
			}
		}

		.title {
			height: 188rpx;
			border-radius: 16rpx;
			border: 1rpx solid #E5E5E5;
			box-sizing: border-box;
			line-height: 188rpx;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #333333;
		}

		.two-row {
			height: 188rpx;
			border-radius: 16rpx;
			border: 1rpx solid #E5E5E5;
			box-sizing: border-box;
			text-align: center;
			font-size: 36rpx;
			font-family: PingFangSC-Medium, PingFang SC;
			font-weight: 500;
			color: #333333;

			.title1 {
				margin-top: 40rpx;
				margin-bottom: 16rpx;
			}

			.content {
				font-size: 30rpx;
				font-family: PingFangSC-Regular, PingFang SC;
				font-weight: 400;
				color: #333333;
			}
		}

		.btn {
			height: 96rpx;
			line-height: 96rpx;
			font-size: 36rpx;
			font-family: PingFangSC-Regular, PingFang SC;
			font-weight: 400;
			display: flex;
			color: #333333;

			.cancel,
			.confirm {
				width: 50%;
				text-align: center;
			}

			.cancel {
				border-right: 1rpx solid #E5E5E5;
			}

			.confirm {
				background-color: #FFFFFF;
				color: #077840;
				border-radius: 0;
				border: none;
				// border-right: 1rpx solid #E5E5E5;
			}

			.confirm::after {
				border: none;
			}
		}

	}

	/* 弹出框 */
	.discount {
		position: fixed;
		bottom: 0;
		width: 100%;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 0px 0px;
		padding: 30rpx 0 24rpx;
		/* height: 299rpx; */
		z-index: 888;
		transform: translate3d(0, 100%, 0);
		transform-origin: center;
		transition: all 0.3s ease-in-out;
		visibility: hidden;
	}

	.discount_dh {
		transform: translate3d(0, 0, 0);
		visibility: visible;
	}

	.tui-actionsheet-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: rgba(0, 0, 0, 0.6);
		z-index: 886;
		transition: all 0.3s ease-in-out;
		opacity: 0;
		visibility: hidden;
	}

	.tui-mask-show {
		opacity: 1;
		visibility: visible;
	}
</style>